package com.jxd.hbase.utils;

import com.jxd.entity.MesContent;
import com.jxd.entity.MesHead;
import com.jxd.repositories.MesHeadRepositories;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


public  class AddHbseContent {

    @Autowired
    MesHeadRepositories mesHeadRepositories;
    @Value("${hbase.bwcontent.tablename}")
    private String bwContentTableName;
    public void  addComMess(){
        List<MesContent> mesContents = new ArrayList<>();
        String mesid ="41040";
        String filename ="20200803.data";
        String shipid="123";
        List<MesHead> mesHeadList =
                mesHeadRepositories.findAllByFileNameAndMesIdAndShipId(filename,mesid,shipid);
        System.out.println(mesHeadList.size());
        String val[] = {"'D0FF'","'D000'","'B0BF'"};

        for (int i = 0; i <mesHeadList.size() ; i++) {
            int n = (int) (Math.random() * 3);
            System.out.println("n========"+n);
            for (int j = 6; j <=2 ; j--) {
                String mesSignId = mesHeadList.get(i).getMesSignId();
                System.out.println(mesSignId);
                System.out.println(val[n]);
                String rowkey = mesSignId+"-"+j;
                if (j==6){
                    MesContent mesContent = new MesContent();
                    mesContent.setRowkey(rowkey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId("6");
                    mesContent.setCode(val[n]);
                    mesContents.add(mesContent);
                }else {
                    MesContent mesContent = new MesContent();
                    mesContent.setRowkey(rowkey);
                    mesContent.setMesSignId(mesSignId);
                    mesContent.setId("6");
                    mesContent.setCode("1111");
                    mesContents.add(mesContent);
                }
            }
        }
        System.out.println("mesContents===="+mesContents.size());
        AddHbase.addHbaseContent("BwContent",mesContents);
        System.out.println("插入开始");
    }


}
